package com.xqb.modules.controller.market;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.MktCouponScope;
import com.xqb.modules.service.IMktCouponScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 优惠券作用范围信息Controller
 * 
 * @author xqb
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/market/scope")
public class MktCouponScopeController extends BaseController
{
    @Autowired
    private IMktCouponScopeService mktCouponScopeService;

    /**
     * 查询优惠券作用范围信息列表
     */
    @PreAuthorize("@ss.hasPermi('market:scope:list')")
    @GetMapping("/list")
    public TableDataInfo list(MktCouponScope mktCouponScope)
    {
        startPage();
        List<MktCouponScope> list = mktCouponScopeService.selectMktCouponScopeList(mktCouponScope);
        return getDataTable(list);
    }

    /**
     * 导出优惠券作用范围信息列表
     */
    @PreAuthorize("@ss.hasPermi('market:scope:export')")
    @Log(title = "优惠券作用范围信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MktCouponScope mktCouponScope)
    {
        List<MktCouponScope> list = mktCouponScopeService.selectMktCouponScopeList(mktCouponScope);
        ExcelUtil<MktCouponScope> util = new ExcelUtil<MktCouponScope>(MktCouponScope.class);
        util.exportExcel(response, list, "优惠券作用范围信息数据");
    }

    /**
     * 获取优惠券作用范围信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:scope:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mktCouponScopeService.selectMktCouponScopeById(id));
    }

    /**
     * 新增优惠券作用范围信息
     */
    @PreAuthorize("@ss.hasPermi('market:scope:add')")
    @Log(title = "优惠券作用范围信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MktCouponScope mktCouponScope)
    {
        return toAjax(mktCouponScopeService.insertMktCouponScope(mktCouponScope));
    }

    /**
     * 修改优惠券作用范围信息
     */
    @PreAuthorize("@ss.hasPermi('market:scope:edit')")
    @Log(title = "优惠券作用范围信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MktCouponScope mktCouponScope)
    {
        return toAjax(mktCouponScopeService.updateMktCouponScope(mktCouponScope));
    }

    /**
     * 删除优惠券作用范围信息
     */
    @PreAuthorize("@ss.hasPermi('market:scope:remove')")
    @Log(title = "优惠券作用范围信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mktCouponScopeService.deleteMktCouponScopeByIds(ids));
    }
}
